package view;

import java.awt.Checkbox;
import java.awt.Color;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import java.util.ArrayList;
/**
 * this class is Graphic user interface of add new Campaign Pattern which extends AbstractGUI
 * @author Moran
 *
 */
public class CampaignPaternGUI extends AbstractGUI {
	
	private JButton cancelButton;//global to all panels
	private JLabel warningMas = null;
	private JPanel CampaignPaternl ;//panel 1 component
	private JButton nextBu = null;
	private JComboBox itemCombo = null;
	private JLabel chooseItem = null;
	private JPanel CampaignPatern2 ;//panel 2 component
	private JButton nextBu2 = null;
	private JTextField agetext=null;
	private JLabel agelable = null;
	private JTextField ratingtext=null;
	private JLabel ratinglable = null;
	private JTextField intresttext=null;
	private JLabel intrestlable = null;
	private JComboBox areaCombo = null;
	private JLabel arealable = null;
	private JButton backButton=null;
	private ArrayList<Checkbox> ck=null;
	int i=0,j=0;
	private JPanel CampaignPatern3 ;//panel 3 component
	private JButton FinishBu = null;
	private JButton backButton2=null;
	private JTextArea massagetext=null;
	private JLabel massagelable = null;
	
	/**
	 * constructor 
	 * this constructor add all the Label, Button,TextField to the Frame and panel 1
	 */
	public CampaignPaternGUI(){
		super();
		cancelButton = new JButton("Cancel");
		cancelButton.setBounds(70, 225, 100, 22);
		CampaignPaternl = new JPanel();
		CampaignPatern2 = new JPanel();
		CampaignPatern3 = new JPanel();
		initPaternl();
	}
	/**
	 * Initialize panel 1
	 */
	public void initPaternl() {
		setTitle(" New Campaign Patern ");
		setBounds(500, 200, 320, 330);
		setSize(320, 330);
		setContentPane(CampaignPaternl());	
	}
	/**
	 * add all the Label, Button,TextField to the panel 1
	 */
	public JPanel CampaignPaternl(){
		this.dispose();
		CampaignPaternl.setLayout(null);
		CampaignPaternl.add(getNextBu());
		CampaignPaternl.add(getItemCombo());
		CampaignPaternl.add(getcancelButton());
		cancelButton.setBounds(10, 244, 100, 22);
		CampaignPaternl.add(getwarningMas());
		nowarningMas();
		warningMas.setBounds(10, 50, 250, 22);
		CampaignPaternl.add(getchooseItem());
		CampaignPaternl.setBackground(Color.lightGray);
		CampaignPaternl.setBounds(500, 200, 300, 250);
		
		setVisible(true);
		return CampaignPaternl;
	}
	/** 
	 * Getters and Setters of panel 1, Button,TextField 
	 */
	public JButton getNextBu() {
		if(nextBu == null){
			nextBu = new JButton("next");
			nextBu.setBounds(164, 244, 100, 22);
		}		
		return nextBu;
	}
	public JComboBox getItemCombo() {
		if(itemCombo == null){
			itemCombo = new JComboBox();
			itemCombo.setBounds(120, 30, 160, 20);
		}
		return itemCombo;
	}
	public JButton getcancelButton() {
		if(cancelButton == null){
			cancelButton = new JButton("Cancel");
			cancelButton.setBounds(24, 254, 100, 22);
		}		
		return cancelButton;
	}
	public JLabel getchooseItem() {
		if(chooseItem == null){
			chooseItem = new JLabel("choose Item: ");
			chooseItem.setBounds(10, 28, 100, 22);
		}
		return chooseItem;
	}
	public JLabel getwarningMas() {
		if(warningMas == null){
			warningMas = new JLabel("");
		
		warningMas.setBounds(10, 50, 250, 22);
		warningMas.setVisible(false);
		}
		return warningMas;
	}
	public void warningMas(String str) {
		warningMas.setText(str);
		warningMas.setVisible(true);
	}
	public void nowarningMas() {
		warningMas.setVisible(false);
	}
	
	public String getItem() {
		if(itemCombo != null)
			return (String)(itemCombo.getSelectedItem());
		return null;
	}
	 /** 
	  * add all the Label, Button,TextField to the Frame and panel 2
	 */
	public void initPatern2() {
		setBounds(500, 200, 400, 430);
		setSize(400, 430);
		setContentPane(CampaignPatern2());	
	}
	/**
	 * Initialize panel 2
	 */
	public JPanel CampaignPatern2(){
		this.dispose();
		//areaCombo=null;
		CampaignPatern2.setLayout(null);
		if(ck==null||ck.isEmpty())
			ck= new ArrayList<Checkbox>();
		CampaignPatern2.add(getNextBu2());
		CampaignPatern2.add(getareaCombo());
		cancelButton.setBounds(30, 340, 100, 22);
		CampaignPatern2.add(getcancelButton());
		CampaignPatern2.add(getAgeFild());
		CampaignPatern2.add(getAgeLable());
		CampaignPatern2.add(getRatingFild());
		CampaignPatern2.add(getwarningMas());
		warningMas.setBounds(10, 290, 250, 22);
		nowarningMas();
		CampaignPatern2.add(getRatingLable());
		CampaignPatern2.add(getIntrestFild());
		CampaignPatern2.add(getIntrestLable());
		//CampaignPatern2.add(getbackButton());
		CampaignPatern2.add(getarealable());
		CampaignPatern2.setBackground(Color.lightGray);
		CampaignPatern2.setBounds(500, 200, 400, 430);
		
		setVisible(true);
		return CampaignPatern2;
	}
	/** 
	 * Getters and Setters of panel 2, Button,TextField 
	 */
	public void getpremishencheckbox(String s) {
		ck.add(new Checkbox(s,null,false));
		if(j==0){
			ck.get(i).setBounds(10, 145+(i*15), 185, 25);
		j++;	
		}
		else{
			ck.get(i).setBounds(200, 145+((i-1)*15), 185, 25);
			j=0;
		}
		CampaignPatern2.add(ck.get(i));
		i++;
	}
	public ArrayList<Checkbox> getck() {
		return ck;
	}
	public JTextField getAgeFild() {
		if(agetext == null){
			agetext = new JTextField("20,50");
			agetext.setBounds(120, 55, 250, 25);
			agetext.setColumns(10);
		}
		return agetext;
	}
	public String getAge() {
		return agetext.getText();	
	}
	public JLabel getAgeLable() {
		if(agelable == null){
			agelable = new JLabel("Custumer Rating:");
			agelable.setBounds(10, 85, 100, 25);
		}
		return agelable;
	}
	public JTextField getRatingFild() {
		if(ratingtext == null){
			ratingtext = new JTextField("0-10");
			ratingtext.setBounds(120, 85, 250, 25);
			ratingtext.setColumns(10);	
		}
		return ratingtext;
	}
	public String getRating() {
		return ratingtext.getText();	
	}
	public JLabel getRatingLable() {
		if(ratinglable == null){
			ratinglable = new JLabel("Interest Level:");
			ratinglable.setBounds(10, 115, 100, 25);
		}
		return ratinglable;
	}
	public JTextField getIntrestFild() {
		if(intresttext == null){
			intresttext = new JTextField("0-10");
			intresttext.setBounds(120, 115, 250, 25);
			intresttext.setColumns(10);	
		}
		return intresttext;
	}
	public String getIntrest() {
		return intresttext.getText();	
	}
	public JLabel getIntrestLable() {
		if(intrestlable == null){
			intrestlable = new JLabel("Custumer Age:");
			intrestlable.setBounds(10, 55, 100, 25);
		}
		return intrestlable;
	}
	public JButton getNextBu2() {
		if(nextBu2 == null){
			nextBu2 = new JButton("next");
			nextBu2.setBounds(230, 340, 100, 22);
		}		
		return nextBu2;
	}
	public JButton getbackButton() {
		if(backButton == null){
			backButton = new JButton("Back");
			backButton.setBounds(130, 340, 100, 22);
		}		
		return backButton;
	}
	public JComboBox getareaCombo() {
		if(areaCombo == null){
			areaCombo = new JComboBox();
			areaCombo.setBounds(120, 30, 160, 20);
		}
		return areaCombo;
	}
	public String getArea() {
		if(areaCombo != null)
			return (String)(areaCombo.getSelectedItem());
		return null;
	}
	public JLabel getarealable() {
		if(arealable == null){
			arealable = new JLabel("choose Area: ");
			arealable.setBounds(10, 28, 100, 22);
		}
		return arealable;
	}
	public ArrayList<String> getPermission(){
		ArrayList<String> arr=new ArrayList<String>();
		for (int i=0 ;i<ck.size();i++){
			if(ck.get(i).getState())
			{
				String temp=new String((ck.get(i)).getLabel());
				arr.add(temp);
			}
		}
		if(arr.isEmpty())
			arr=null;
		return arr;
	}
	 /** 
	  * add all the Label, Button,TextField to the Frame and panel 3
	 */
	public void initPatern3() {
		setBounds(500, 200, 400, 430);
		setSize(400, 430);
		setContentPane(CampaignPatern3());	
	}
	/**
	 * Initialize panel 3
	 */
	public JPanel CampaignPatern3(){
		this.dispose();
		CampaignPatern3.setLayout(null);
		CampaignPatern3.add(getFinishBu());
		cancelButton.setBounds(30, 340, 100, 22);
		CampaignPatern3.add(getcancelButton());
		CampaignPatern3.add(getmassagetext());
		CampaignPatern3.add(getmassagelable());
		CampaignPatern3.add(getwarningMas());
		warningMas.setBounds(10, 290, 250, 22);
		nowarningMas();
	//	CampaignPatern3.add(getbackButton2());
		CampaignPatern3.setBackground(Color.lightGray);
		CampaignPatern3.setBounds(500, 200, 400, 430);
		
		setVisible(true);
		return CampaignPatern3;
	}
	/** 
	 * Getters and Setters of panel 3, Button,TextField 
	 */
	public JButton getFinishBu() {
		if(FinishBu == null){
			FinishBu = new JButton("Finish");
			FinishBu.setBounds(230, 340, 100, 22);
		}		
		return FinishBu;
	}
	public JTextArea getmassagetext() {
		if(massagetext == null){
			massagetext = new JTextArea("");
			massagetext.setBounds(10, 36, 360,255);
			massagetext.setColumns(10);
		}
		return massagetext;
	}
	public String getmassagestr() {
		return massagetext.getText();
	}
	public JLabel getmassagelable() {
		if(massagelable == null){
			massagelable = new JLabel("Add text message:");
			massagelable.setBounds(10, 10, 200, 25);
		}
		return massagelable;
	}
	public JButton getbackButton2() {
		if(backButton2 == null){
			backButton2 = new JButton("Back");
			backButton2.setBounds(130, 340, 100, 22);
		}
		return backButton2;
	}

	/**
	 * add to cancel button ActionListener
	 * @param listener
	 */
	public void addcancelButtonlesrepor(ActionListener listener){
		cancelButton.addActionListener(listener);
	}
	/**
	 * add to next button ActionListener
	 * @param listener
	 */
	public void addNextBottonActionListener(ActionListener listener){
		nextBu.addActionListener(listener);
	} 
	/**
	 * add to next2 button ActionListener
	 * @param listener
	 */
	public void addNextBotton2ActionListener(ActionListener listener){
		nextBu2.addActionListener(listener);
	} 
	/**
	 * add to back button ActionListener
	 * @param listener
	 */
	public void addbackActionListener(ActionListener listener){
		backButton.addActionListener(listener);
	}
	/**
	 * add to finish button ActionListener
	 * @param listener
	 */
	public void addFinishBottonActionListener(ActionListener listener){
		FinishBu.addActionListener(listener);

	} 
	/**
	 * add to back2 button ActionListener
	 * @param listener
	 */
	public void addback2ActionListener(ActionListener listener){
		backButton2.addActionListener(listener);
	}
}
